package com.zhumei.keyscale.server;

import android.app.*;
import com.zhumei.keyscale.ui.*;
import android.util.*;
import android.hardware.display.*;
import com.blankj.utilcode.util.*;
import android.os.*;
import android.provider.*;
import android.content.*;
import android.view.*;

public class DualScreenService extends Service
{
    private CommercialScreenPresentation mPresentation;
    private SparseArray<CommercialScreenPresentation> mPresentations;
    
    public DualScreenService() {
        this.mPresentations = (SparseArray<CommercialScreenPresentation>)new SparseArray();
    }
    
    private void destoryPresentation() {
        ((CommercialScreenPresentation)this.mPresentations.get(1)).dismiss();
        this.mPresentations = null;
    }
    
    public IBinder onBind(final Intent intent) {
        return null;
    }
    
    public void onCreate() {
        super.onCreate();
    }
    
    public void onDestroy() {
        super.onDestroy();
        this.destoryPresentation();
        this.stopSelf();
    }
    
    public int onStartCommand(final Intent intent, final int n, final int n2) {
        final DisplayManager displayManager = (DisplayManager)this.getApplicationContext().getSystemService("display");
        if (ObjectUtils.isNotEmpty(displayManager)) {
            final Display[] displays = displayManager.getDisplays();
            if (ObjectUtils.isNotEmpty(displays)) {
                if (displays.length > 1) {
                    if (this.mPresentation == null) {
                        this.mPresentation = new CommercialScreenPresentation(this.getApplicationContext(), displays[1]);
                    }
                    LogUtils.d(" mPresentation", this.mPresentation.toString());
                    final Window window = this.mPresentation.getWindow();
                    this.mPresentations.put(1, (Object)this.mPresentation);
                    if (ObjectUtils.isNotEmpty(window)) {
                        if (Build$VERSION.SDK_INT >= 26) {
                            window.setType(2038);
                        }
                        else {
                            window.setType(2003);
                        }
                        if (Build$VERSION.SDK_INT >= 23) {
                            final boolean canDrawOverlays = Settings.canDrawOverlays((Context)this);
                            final StringBuilder sb = new StringBuilder();
                            sb.append("open : ");
                            sb.append(canDrawOverlays);
                            LogUtils.d(sb.toString());
                            if (canDrawOverlays) {
                                this.mPresentation.show();
                            }
                            else {
                                this.startActivity(new Intent("android.settings.action.MANAGE_OVERLAY_PERMISSION"));
                            }
                        }
                        else {
                            this.mPresentation.show();
                        }
                    }
                }
                else {
                    LogUtils.e("DISPLAYS.LENGTH <= 1");
                }
            }
        }
        return super.onStartCommand(intent, n, n2);
    }
}
